package com.qiaofang.applet.config;

import com.qiaofang.applet.filter.RequestFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author QF2019
 */
@Configuration
public class FilterConfig {

    @Autowired
    private RequestFilter requestFilter;

    /**
     * 通过header初始化QfContext上下文Filter
     * @return
     */
    @Bean
    public FilterRegistrationBean registWebsiteFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(requestFilter);
        registration.addUrlPatterns("/api/*");
        registration.setName("requestFilter");
        // 值越小，Filter越靠前
        registration.setOrder(1);
        return registration;
    }
}
